$(function() {
			$("#form1").ligerForm({
						inputWidth : 200,
						labelWidth : 120,
						space : 40

					});

			var successFunc = function(responseText, statusText) {
				if (statusText == "success") {
					var json = param2json(responseText);
					if (json.success) {
						alert("财务信息上传成功");
						listAnnex();
					} else {
						alert(json.msg);
					}
				} else {
					alert("财务信息上传失败");
				}
			}

			$("#Button1").click(function() {
				grooveRemixSubmit("fcapply", "-1", "single", null, $("#form1"),
						function() {
							var r = false;
							for (var i = 0; i < $(":file").length; i++) {
								if ($(":file")[i].value != "") {
									r = true;
									break;
								}
							}
							if (!r) {
								alert("请上传财务信息相关附件");
							}
							return r;
						}, successFunc)
			});

			listAnnex();
		});

function listAnnex() {
	var options = {
		tableName : "fcapply",
		handleType : "single",
		id : $("#pkid").val(),
		initFunc : function(data) {
			if (data.FC_BALANCESHEET1 != null || data.FC_BALANCESHEET2 != null
					|| data.FC_BALANCESHEET3 != null) {
				if ($("#group1").length == 0) {
					$("<div class=\"l-group\" id=\"group1\" style=\"width: 700px;\"><span>资产负债表</span></div>")
							.appendTo($("#form1"));
					$("<div id=\"group1area\" style=\"width: 700px;\"></div>")
							.appendTo($("#form1"));
				}
			}
			//
			if (data.FC_BALANCESHEET1 != null) {
				$("#fcbalancesheet1").attr("disabled", true);
				$.each(data.FC_BALANCESHEET1, function(i, file) {
							initAnnex(file, $("#group1"), $("#group1area"), $("#fcbalancesheet1"));
						});
			}

			//
			if (data.FC_BALANCESHEET2 != null) {
				$("#fcbalancesheet2").attr("disabled", true);
				$.each(data.FC_BALANCESHEET2, function(i, file) {
							initAnnex(file, $("#group1"), $("#group1area"), $("#fcbalancesheet2"));
						});
			}

			//
			if (data.FC_BALANCESHEET3 != null) {
				$("#fcbalancesheet3").attr("disabled", true);
				$.each(data.FC_BALANCESHEET3, function(i, file) {
							initAnnex(file, $("#group1"), $("#group1area"), $("#fcbalancesheet3"));
						});
			}

			if (data.FC_INCOMESTATEMENT1 != null
					|| data.FC_INCOMESTATEMENT2 != null
					|| data.FC_INCOMESTATEMENT3 != null) {
				if ($("#group2").length == 0) {
					$("<div class=\"l-group\" id=\"group2\" style=\"width: 700px;\"><span>损益表</span></div>")
							.appendTo($("#form1"));
					$("<div id=\"group2area\" style=\"width: 700px;\"></div>")
							.appendTo($("#form1"));
				}
			}
			//
			if (data.FC_INCOMESTATEMENT1 != null) {
				$("#fcincomestatement1").attr("disabled", true);
				$.each(data.FC_INCOMESTATEMENT1, function(i, file) {
							initAnnex(file, $("#group2"), $("#group2area"), $("#fcincomestatement1"));
						});
			}

			//
			if (data.FC_INCOMESTATEMENT2 != null) {
				$("#fcincomestatement2").attr("disabled", true);
				$.each(data.FC_INCOMESTATEMENT2, function(i, file) {
							initAnnex(file, $("#group2"), $("#group2area"), $("#fcincomestatement2"));
						});
			}

			//
			if (data.FC_INCOMESTATEMENT3 != null) {
				$("#fcincomestatement3").attr("disabled", true);
				$.each(data.FC_INCOMESTATEMENT3, function(i, file) {
							initAnnex(file, $("#group2"), $("#group2area"), $("#fcincomestatement3"));
						});
			}

			if (data.FC_IOCONTRACT != null) {
				if ($("#group3").length == 0) {
					$("<div class=\"l-group\" id=\"group3\" style=\"width: 700px;\"><span>进销货合同</span></div>")
							.appendTo($("#form1"));
					$("<div id=\"group3area\" style=\"width: 700px;\"></div>")
							.appendTo($("#form1"));
				}
			}
			//
			if (data.FC_IOCONTRACT != null) {
				$("#fciocontract").attr("disabled", true);
				$.each(data.FC_IOCONTRACT, function(i, file) {
							initAnnex(file, $("#group3"), $("#group3area"), $("#fciocontract"));
						});
			}
		}
	}

	grooveTableSelector(options);
}

function initAnnex(file, group, grouparea, fileInput) {
	var fileId = file.id;
	var divId = "div_" + fileId;

	if ($("#" + divId).length == 0) {
		var fileType = file.type;
		var fileName = file.name + "." + fileType;

		/*
		 * var img = $("<img src=\"" + context +
		 * "/site/focalCompany/images/bullet_delete.png\"/>"); img.attr("title",
		 * "删除文件"); // img.css("cursor", "hand"); img.click(function() {
		 * deleteAnnex(fileId, function(responseData) { $("#div_" +
		 * fileId).remove(); }); });
		 */
		var loadA = $("<a>下载保存</a>");
		loadA.attr("href", "javascript:void(0)");
		loadA.attr("title", "下载保存文件");
		loadA.css("color", "#666");
		loadA.css("font-size", "12px");
		loadA.css("padding-left", "10px");
		loadA.css("cursor", "hand");
		loadA.click(function() {
					downloadAnnex(fileId);
				});

		var delA = $("<a>删除</a>");
		delA.attr("href", "javascript:void(0)");
		delA.attr("title", "删除文件");
		delA.css("color", "#666");
		delA.css("font-size", "12px");
		delA.css("padding-left", "10px");
		delA.css("cursor", "hand");
		delA.click(function() {
					deleteAnnex(fileId, function(responseData) {
								$("#div_" + fileId).remove();
								if (grouparea.children().length == 0) {
									group.remove();
									grouparea.remove();
								}
								fileInput.attr("disabled", false);
							});
				});

		var a = $("<a>" + fileName + "</a>");
		a.attr("href", "javascript:void(0)");
		a.attr("title", "点击预览文件");
		a.click(function() {
					viewAnnex(fileName, fileId);
				});

		$("<div id=\"" + divId + "\"></div>").css("padding", "3px").append(a)
				.append(loadA).append(delA).appendTo(grouparea);
	}
}